﻿@model LoginModel
@{
    Layout = "_LayoutLogin";
    ViewData["Title"] = "用户登录";
    int checkResult = ViewBag.CheckConnection ?? 0;
}

<!-- 登录表单 -->
<form method="post" asp-controller="account" asp-action="login" enctype="multipart/form-data">
    <h2 class="form-caption">欢迎回来</h2>

    <div class="row mb-4">
        <label class="form-label" for="username">用户名</label>
        <div class="position-relative">
            <i class="login-ico login-ico-input login-ico-input-user"></i>
            <input type="text" class="form-control login-input-with-ico" id="username" name="username" placeholder="请输入用户名" asp-for="UserName" value="@Model?.UserName">
        </div>
        <span asp-validation-for="UserName" class="text-danger small"></span>
    </div>

    <div class="row mb-4">
        <label class="form-label" for="password">密码</label>
        <div class="position-relative">
            <i class="login-ico login-ico-input login-ico-input-password"></i>
            <input type="password" class="form-control login-input-with-ico" id="password" name="password" placeholder="请输入密码" asp-for="Password" value="123456">
        </div>
        <span asp-validation-for="Password" class="text-danger small"></span>
    </div>

    <div class="row-cols-2 mb-4 text-center">
        <button type="submit" class="btn btn-primary form-button">登录系统</button>
        <input id="hidMsg" type="hidden" value="@Model?.ResultMessage" />
        <input id="hidCheck" type="hidden" value="@checkResult" />
    </div>

    <div class="row-cols-2 mb-4 text-center">
        还没有账号? <a asp-controller="account" asp-action="register">立即注册</a>
    </div>
</form>

@section Scripts {
    <script type="text/javascript">
        window.addEventListener("DOMContentLoaded",function(){
            var check = document.querySelector("#hidCheck").value;
            if(check=="1")
                console.log("%c程序自检完成！","color:blue");
            else
                console.log("%c程序自检中...","color:red");
        });
        window.onload = function(){
            var msg = document.querySelector("#hidMsg").value;
            if(msg && msg.length > 0){
                showMessage("用户登录", msg);
            }
        };
    </script>
}